/*-----------------------------------------
file name  : rdy_driver.sv
created    : 2025/10/04 10:32:27
modified   : 2025-10-04 11:39:58
description: 
notes      : 
author     : yyrwkk
-----------------------------------------*/
`ifndef RDY_DRIVER__SV
`define RDY_DRIVER__SV
class rdy_driver extern uvm_driver # (rdy_trans) ;
    `uvm_component_utils(rdy_driver)
    
    virtual rdy_if rdy_vif; 
    uvm_blocking_get_port#(rdy_trans) from_rdy_generator_bp;

    extern function new(string name="rdy_driver", uvm_componet parent=null);
    extern function void build_phase( uvm_phase phase );
    extern task main_phase(uvm_phase phase);
    extern task drive_one_trans(rdy_trans tr);
endclass

function rdy_driver::new(string name="rdy_driver", uvm_componet parent=null);
    super.new(name,parent)
endfunction 

function void rdy_driver::build_phase( uvm_phase phase );
    super.build_phase( uvm_phase phase );
    if(!uvm_config_db#(virtual rdy_if)::get(this,"","rdy_if",rdy_vif)) 
        `uvm_fatal(get_full_name(),"get rdy_if failed !")

    from_rdy_generator_bp = new();
    `uvm_info("rdy_driver","build_phase done!",UVM_MEDIUM)
endfunction 

task rdy_driver:drive_one_trans(rdy_trans tr);
    rdy_vif.drv.rdy <= tr.rdy_cfg.init_rdy_value;
    repeat(tr.duration_time) @rdy_vif.drv;
    rdy_vif.drv.rdy <= ~tr.rdy_cfg.init_rdy_value;
    repeat(tr.interval_time) @rdy_vif.drv;
endtask

task rdy_dirver::main_phase(uvm_phase phase);
    super.main_phase(phase);
    forever begin 
        from_rdy_generator_bp.get(req);
        drive_one_trans(req);
    end
endtask

`endif

